package com.hamishmedlin.psxpw;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class DecoderTest {

	@Test
	public void defaultSettings() {
		try {
			FormData fd = QDecoder.decodePassword("VBVXVVXVVV");
			assertEquals(1, fd.getNextMap());
			assertEquals(QGlobals.SKILL_WIMP, fd.getGameSkill());
			assertEquals(fd.getChecked(QGlobals.BACKPACK), false);
			for(String weapon : QGlobals.weaponControlForIndex){
				if(weapon.equals(QGlobals.WEAPON_FIST) || weapon.equals(QGlobals.WEAPON_PISTOL)){
					assertEquals(true, fd.getChecked(weapon));
					continue;
				}				
				assertEquals(false, fd.getChecked(weapon));				
			}
			
			assertEquals(50, fd.getClip());
			assertEquals(0, fd.getShell());
			assertEquals(0, fd.getRockets());
			assertEquals(0, fd.getCell());
			assertEquals(100, fd.getHealth());
			assertEquals(0, fd.getArmor());
			assertEquals(QGlobals.ARMOR_NONE, fd.getArmorType());
		} catch (FailedDecode e) {
			e.printStackTrace();
		}
		
		
	}
	
	@Test
	public void everything() {
		try {
			FormData fd = QDecoder.decodePassword("M51W3PRCPM");
			assertEquals(1, fd.getNextMap());
			assertEquals(QGlobals.SKILL_WIMP, fd.getGameSkill());
			assertEquals(fd.getChecked(QGlobals.BACKPACK), true);
			for(String weapon : QGlobals.weaponControlForIndex){
				assertEquals(true, fd.getChecked(weapon));				
			}
			
			assertEquals(400, fd.getClip());
			assertEquals(100, fd.getShell());
			assertEquals(100, fd.getRockets());
			assertEquals(600, fd.getCell());
			assertEquals(200, fd.getHealth());
			assertEquals(200, fd.getArmor());
			assertEquals(QGlobals.ARMOR_BLUE, fd.getArmorType());
		} catch (FailedDecode e) {
			e.printStackTrace();
		}		
	}
	
	@Test
	public void levelSkillArmor(){
		try {
			FormData fd = QDecoder.decodePassword("!9DBDDBBFD");
			assertEquals(59, fd.getNextMap());
			assertEquals(QGlobals.SKILL_ULTRA, fd.getGameSkill());
			assertEquals(fd.getChecked(QGlobals.BACKPACK), false);
			for(String weapon : QGlobals.weaponControlForIndex){
				if(weapon.equals(QGlobals.WEAPON_FIST) || weapon.equals(QGlobals.WEAPON_PISTOL)){
					assertEquals(true, fd.getChecked(weapon));
					continue;
				}				
				assertEquals(false, fd.getChecked(weapon));				
			}
			
			assertEquals(50, fd.getClip());
			assertEquals(0, fd.getShell());
			assertEquals(0, fd.getRockets());
			assertEquals(0, fd.getCell());
			assertEquals(100, fd.getHealth());
			assertEquals(50, fd.getArmor());
			assertEquals(QGlobals.ARMOR_GREEN, fd.getArmorType());
		} catch (FailedDecode e) {
			e.printStackTrace();
		}
	}
}
